package com.wkk.nursinghome.dao;

import com.wkk.nursinghome.domain.Withdrawal;
import org.apache.ibatis.jdbc.SQL;

public class WithdrawalSQLProvider {
    //动态语句执行修改
    public String updateWithdrawal(Withdrawal withdrawal){
        return new SQL(){
            {
                UPDATE("withdrawal");
                if(null!=withdrawal.getName()){
                    SET("name=#{name}");
                }
                if(null!=withdrawal.getSex()){
                    SET("sex=#{sex}");
                }
                if(null!=withdrawal.getAge()){
                    SET("age=#{age}");
                }
                if(null!=withdrawal.getFnumber()){
                    SET("fnumber=#{fnumber}");
                }
                if(null!=withdrawal.getCitime()){
                    SET("citime=#{citime}");
                }
                if(null!=withdrawal.getWithdrawaltime()){
                    SET("withdrawaltime=#{withdrawaltime}");
                }
                if(null!=withdrawal.getWithdrawatype()){
                    SET("withdrawatype=#{withdrawatype}");
                }
                if(null!=withdrawal.getWithdrawareason()){
                    SET("withdrawareason=#{withdrawareason}");
                }
                if(null!=withdrawal.getStatus()){
                    SET("status=#{status}");
                }
                if(null!=withdrawal.getApptime()){
                    SET("apptime=#{apptime}");
                }
                if(null!=withdrawal.getAuditopinion()){
                    SET("auditopinion=#{auditopinion}");
                }
                if(null!=withdrawal.getReviewer()){
                    SET("reviewer=#{reviewer}");
                }
                if(null!=withdrawal.getReviewtime()){
                    SET("reviewtime=#{reviewtime}");
                }
                if(null!=withdrawal.getRemarks()){
                    SET("remarks=#{remarks}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
    }
    //根据条件查询信息
    public String selectWithdrawalByCondition(Withdrawal withdrawal){
        return new SQL(){
            {
                SELECT("*");
                FROM("withdrawal");
                //使用动态SQL拼接查询条件
                if(null!=withdrawal.getName()){
                    WHERE("name like concat('%',#{name},'%')");
                }
                if(null!=withdrawal.getFnumber()){
                    WHERE("fnumber=#{fnumber}");
                }
            }
        }.toString();
    }
}
